package org.songwang.org.controller;


import org.songwang.basic.AjaxResult;
import org.songwang.basic.PageList;
import org.songwang.org.domain.Systemdictionarydetail;
import org.songwang.org.query.SystemdictionarydetailQuery;
import org.songwang.org.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;

    @GetMapping
    public List<Systemdictionarydetail> findAll() {
        return systemdictionarydetailService.findAll();
    }

    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id") Long id) {
        System.out.println(id);
        return systemdictionarydetailService.findById(id);
    }

    @PutMapping
    public AjaxResult add(@RequestBody Systemdictionarydetail systemdictionarydetail) {
        try {
            if (systemdictionarydetail.getId() == null) {
                systemdictionarydetailService.add(systemdictionarydetail);
            } else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败").setSuccess(false);
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
            systemdictionarydetailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败").setSuccess(false);
        }
    }

    @PostMapping
    public PageList findQuery(@RequestBody SystemdictionarydetailQuery query) {
        return systemdictionarydetailService.findQuery(query);
    }
}
